import java.io.IOException;
import java.io.PrintStream;

import static java.lang.String.format;

/**
 * Created by balau on 3/6/14.
 * again?  hellloooo!
 */
public class TicTacToeApp {

    String [] gameState;
    PrintStream printStream;
    private final UserIO userIO;

    public TicTacToeApp(PrintStream printStream, UserIO userIO) {
        this.printStream = printStream;
        this.userIO = userIO;
        this.gameState = new String[9];
        for (int i = 0; i < 9; i++) {
            gameState[i] = " ";
        }
    }
    public static void main(String[] args) throws IOException {
        TicTacToeApp app = new TicTacToeApp(System.out,new UserIO());
        app.start();
    }

    public void start() throws IOException {

        Board board = new Board(System.out, gameState);
        board.print();

        printStream.println(askPlayerForMove(1));

        Player player = new Player(userIO);
        int input = player.getInput();
        gameState = board.update(1,"X");
        printStream.println(printGameState());
    }

    public String askPlayerForMove(int userNumber) {
        return format("User %d, please make a move.  Enter a number between 1 and 9: ",userNumber);
    }

    public String printGameState() {
        return format(" %s | %s | %s \n___________\n %s | %s | %s \n___________\n %s | %s | %s ",
                gameState[0],
                gameState[1],
                gameState[2],
                gameState[3],
                gameState[4],
                gameState[5],
                gameState[6],
                gameState[7],
                gameState[8]);
    }

}
